package de.tg.handball.xml;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Vector;

public class RSSFeed {
	private String _title = null;
	private Date _pubdate = null;
	private int _itemcount = 0;
	private List<RSSItem> _itemlist;

	RSSFeed() {
		_itemlist = new Vector<RSSItem>(0);
	}

	int addItem(RSSItem item) {
		_itemlist.add(item);
		_itemcount++;
		return _itemcount;
	}

	RSSItem getItem(int location) {
		return _itemlist.get(location);
	}

	public List<RSSItem> getAllItems() {
		Collections.sort(_itemlist);
		return _itemlist;
	}

	int getItemCount() {
		return _itemcount;
	}

	void setTitle(String title) {
		_title = title;
	}

	void setPubDate(Date pubdate) {
		_pubdate = pubdate;
	}

	String getTitle() {
		return _title;
	}

	Date getPubDate() {
		return _pubdate;
	}

	@Override
	public String toString() {
		return "Titel: "+_title + " pubdate: "+ _pubdate + " ItemCount: "+ _itemcount+ "\n"+ itemsToString();
	}
	
	private String itemsToString(){
		String ret = "";
		for (RSSItem item : _itemlist) {
			ret +=item.toString() +"\n";
		}
		return ret;
	}
	
}
